
export function getWeekDate(date) {
    var now = new Date(date);
    var day = now.getDay();
    var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    var week = weeks[day];
    return week;
}


export function getWeekDateNew(date) {
    let weeks = {
        1 : '星期一',
        2 : '星期二',
        3 : '星期三',
        4 : '星期四',
        5 : '星期五',
        6 : '星期六',
        7 : '星期日',
    }
    var week = weeks[date];
    return week;
}

export function getMonthWeek(a, b, c) {
    /**
    * a = d = 当前日期
    * b = 6 - w = 当前周的还有几天过完(不算今天)
    * a + b 的和在除以7 就是当天是当前月份的第几周
    */
    let date = new Date(a, parseInt(b) - 1, c),
        w = date.getDay(),
        d = date.getDate();
    if(w==0){
        w=7;
    }
    let config={
        getMonth:date.getMonth()+1,
        getYear:date.getFullYear(),
        getWeek:Math.ceil((d + 6 - w) / 7),
    }
    return config;
};

export function getTime (d) {
    var date = new Date(d)
    let t = ''
    let time = ''
    t = date.getHours()
    time += `${t.toString().length === 2 ? t : ('0' + t)}` + '.'

    t = date.getMinutes()
    time += `${t.toString().length === 2 ? t : ('0' + t)}`
    return time
}

export function formatDate(date){
    let time = ''
    let y = new Date(date).getFullYear()
    let month = (new Date(date).getMonth() + 1) < 10 ? '0' + (new Date(date).getMonth() + 1) : (new Date(date).getMonth() + 1)
    let day = new Date(date).getDate() < 10 ? '0' + new Date(date).getDate() : new Date(date).getDate() 
    let hour = new Date(date).getHours() < 10 ? '0' + new Date(date).getHours() : new Date(date).getHours() 
    let minute = new Date(date).getMinutes() < 10 ? '0' + new Date(date).getMinutes() : new Date(date).getMinutes() 
    let second = new Date(date).getSeconds() < 10 ? '0' + new Date(date).getSeconds() : new Date(date).getSeconds() 
    time = y + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
    return time
}

export function formatDateArray(date){
    let y = new Date(date).getFullYear() + ''
    let month = (new Date(date).getMonth() + 1) >= 10 ? (new Date(date).getMonth() + 1) + '' : '0' + (new Date(date).getMonth() + 1)
    let d = new Date(date).getDate()>= 10 ? new Date(date).getDate() + '': '0'+ new Date(date).getDate()
    let h = new Date(date).getHours(date) >= 10 ? new Date(date).getHours() + '' : '0' + new Date(date).getHours() 
    let minute = new Date(date).getMinutes() >= 10 ? new Date(date).getMinutes() + '' : '0' + new Date(date).getMinutes()
    let s = new Date(date).getSeconds() >= 10 ? new Date(date).getSeconds() + '' : '0' + new Date(date).getSeconds()
    return {
        y,month,d,h,minute,s
    }
}

export function getDate(date,num,type){
     let newDate 
    if(type === 'add'){
        newDate = new Date(date.getTime() + (1000*60*60*24*num))
    }else{
        newDate = new Date(date.getTime() - (1000*60*60*24*num))
    }
    return formatDateArray(newDate)
}


export function HTMLParse(text){
    
}